package cn.topkinson.lagou.s3m4.code.controller;

import cn.topkinson.lagou.s3m4.code.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author huangzihao
 * @Date 2020/9/9 15:39
 */
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    /**
     * ⽣成验证码并发送到对应邮箱，成功true，失败 false
     * @param email
     * @return
     */
    @GetMapping("/create/{email}")
    public Boolean create(@PathVariable String email){
        return codeService.create(email);
    }

    /**
     * 校验验证码是否正确，0正确1错误2超时
     * @param email
     * @return
     */
    @GetMapping("/validate/{email}/{code}")
    public Integer validate(@PathVariable String email,@PathVariable String code){
        return codeService.validate(email,code);
    }
}
